module.exports = {
    apiHost: 'https://uapi.zheshouka.com',
    // apiHost: 'https://test-uapi.zheshouka.com',
    kefu: "https://10929311.saas.53kf.com/code/xcx/6cc83c5322375084d7ce617c094303f52/1'",
    title: '浙收卡',
    httpUrl: 'https://uapi.zheshouka.com', //图片地址
    id: '', //自己的id
    assets: '', //推广的id
    appToken: '', //微信登录的token
    background: false,
    getAuthCode: function () {
        var authcode = uni.getStorageSync('authcode');
        if (!authcode) {
            authcode = this.getCookie('authcode');
        }
        return authcode || '';
    },

    setAuthCode: function ($authcode) {
        uni.setStorageSync('authcode', $authcode);
    },

    appwxlogin(users) {
        var _this = this;
        uni.request({
            url: _this.apiHost + '/appWxLogin',
            method: 'POST',
            data: users,
            header: {
                Authorization: ''
            },
            success: (res) => {
                console.log(res.data);

                if (res.data.code == 0) {
                    _this.setAuthCode(res.data.token);
                    uni.setStorageSync('users', JSON.stringify(res.data.user));
                    _this.showMsg('登陆成功', '../my/my');
                } else if (res.data.code == 1) {
                    _this.showMsg(res.data.msg);
                } else if (res.data.code == 2) {
                    _this.showMsg('请先绑定账户', '../login/binduser?token=' + res.data.token);
                }
            },
            fail: (res) => {
                console.log(res);
            }
        });
    },

    getLoginToken(code, qrcode) {
        var that = this;
        uni.request({
            url: this.apiHost + '/getLoginToken',
            method: 'post',
            header: {
                Authorization: ''
            },
            data: {
                qrcode: qrcode,
                code: code
            },
            success: (res) => {
                console.log(res.data);
                let data = res.data;
                if (data.code == 1) {
                    that.setAuthCode(data.data.token);
                    uni.setStorageSync('users', JSON.stringify(data.data.user));
                    console.log(987454544);
                    uni.navigateTo({
                        url: '../my/my'
                    });
                } else if (data.code == 2) {
                    uni.navigateTo({
                        url: '../login/binduser?token=' + data.data.token
                    });
                } else {
                    uni.showToast({
                        title: data.msg,
                        icon: 'none'
                    });
                }
            },
            fail: (e) => {
                uni.showToast({
                    title: '链接失败',
                    icon: 'error'
                });
            }
        });
    },

    islogin: function (qrcode) {
        var that = this;
        uni.request({
            url: that.apiHost + '/getAppid',
            method: 'post',
            data: {
                qrcode: qrcode
            },
            success: (res) => {
                console.log(res.data);
                let data = res.data;
                if (data.code == 0) {
                    let tourlb = data.data.redurl;
                    console.log(tourlb);
                    location.href = tourlb;
                }
            },
            fail: (e) => {
                uni.showToast({
                    title: '链接失败',
                    icon: 'error'
                });
            }
        });
    },

    showMsg: function (msg, url) {
        var url = url || '';
        uni.showToast({
            title: msg,
            icon: 'none',
            position: 'bottom',
            success: function () {
                if (url != '') {
                    setTimeout(function () {
                        uni.navigateTo({
                            url: url
                        });
                    }, 1100);
                }
            }
        });
    },
    getCookie: function (name) {
        // #ifdef H5
        var strcookie = document.cookie;
        var arrcookie = strcookie.split('; ');
        for (var i = 0; i < arrcookie.length; i++) {
            var arr = arrcookie[i].split('=');
            if (arr[0] == name) {
                return arr[1];
            }
        }
        return '';
        // #endif
    }
};
